package com.jianganming.chain;


import com.mysql.cj.util.StringUtils;

import java.util.Map;

public class ValidateHandler extends Handler<Member> {
    @Override
    public void doHandler(Member member) {
        DateSource dateSource = DateSource.getDateSourceInstance();
        Map<String, User> userMap = dateSource.getUser();
        if(StringUtils.isNullOrEmpty(member.getLoginName()) ||
                StringUtils.isNullOrEmpty(member.getLoginPass())){
            System.out.println("用户名或者密码不能为空");
        }else {
            User user = userMap.get(member.getLoginName());
            if(user == null){
                System.out.println("用户名不存在");
            }else if(!user.getPassword().equals(member.getLoginPass())){
                System.out.println("密码错误");
            }else {
                if(null != next) {
                    System.out.println("账号校验成功");
                    next.doHandler(member);
                }
            }
        }

    }
}
